//
//  ADMainController.swift
//  myBlog
//
//  Created by mac2014 on 16/3/20.
//  Copyright © 2016年 AD. All rights reserved.
//

import UIKit


class ADMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.setValue(ADMainTabBar(), forKey: "tabBar")

        addChildViewControllers()
    }
    
    /**
     添加控制器
     */
    func addChildViewControllers() {
        let homeVC = ADHomeViewController()
        addChildViewController(homeVC, title: "首页", image:"tabbar_home")
        
        let massageVC = ADMassageController()
        addChildViewController(massageVC, title: "消息", image:"tabbar_message_center")
        
        let discoverVC = ADDiscoverController()
        addChildViewController(discoverVC, title: "发现", image: "tabbar_discover")
        
        let profileVC = ADProfileController()
        addChildViewController(profileVC, title: "我", image: "tabbar_profile")
    }
    
    //添加子控制器
    func addChildViewController(controller: UIViewController, title: String, image: String) {
//        let homeVC = ADHomeViewController()
//        homeVC.title = "首页"
//        homeVC.tabBarItem.image = UIImage(named: "tabbar_home")
//        tabBarVC.addChildViewController(UINavigationController(rootViewController: homeVC))
        //标题
        controller.title = title
        //图片
        controller.tabBarItem.image = UIImage(named: image)
        //设置高亮图片
        let highlightImageName = image + "_highlighted"
        controller.tabBarItem.selectedImage = UIImage(named: highlightImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置字体颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加导航栏控制器
        addChildViewController(UINavigationController(rootViewController: controller))
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
